

package classloading.domain;

import javax.cache.configuration.Factory;
import javax.cache.integration.CacheLoader;
import javax.cache.integration.CacheLoaderException;
import java.io.Serial;
import java.util.HashMap;
import java.util.Map;

public class PersonCacheLoaderFactory implements Factory<CacheLoader<String, Person>> {
    @Serial
    private static final long serialVersionUID = 1L;

    @Override
    public CacheLoader<String, Person> create() {
        return new CacheLoader<>() {
            @Override
            public Person load(String k) throws CacheLoaderException {
                return new Person();
            }

            @Override
            public Map<String, Person> loadAll(Iterable<? extends String> itrbl) throws CacheLoaderException {
                Map<String, Person> rv = new HashMap<>();
                for (String it : itrbl) {
                    rv.put(it, load(it));
                }
                return rv;
            }
        };
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof PersonCacheLoaderFactory;
    }
}
